<template>
  <div
    class="userLike"
    v-if="likes.length > 0 && this.$route.query.userid != 13525021"
  >
    <UserLikeItem v-for="like in likes" :key="like.resource.id" :like="like" />
  </div>
  <div
    class="userLike"
    v-else-if="likes.length > 0 && this.$route.query.userid == 13525021"
  >
    <MineLikeItem v-for="like in likes" :key="like" :likeId="like" />
  </div>
  <div class="none" v-else>还没有喜欢的作品</div>
</template>

<script>
import UserLikeItem from "@/components/UserLikeItem.vue";
import MineLikeItem from "@/components/MineLikeItem.vue";

export default {
  components: {
    UserLikeItem,
    MineLikeItem,
  },
  data() {
    return {
      likes: [],
      next: null,
    };
  },
  created() {
    if (this.$route.query.userid == 13525021) {
      this.likes = JSON.parse(localStorage.getItem("nsLikes") || "[]");
    } else {
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });
      this.$axios
        // .get(`https://apis.netstart.cn/xpc/user/${this.$route.query.userid}/articles`)
        .get(
          `https://apis.netstart.cn/xpc/user/${this.$route.query.userid}/articles-approved`
        )
        .then((res) => {
          // console.log(res.data.data);
          this.likes = res.data.data.list;
          this.next = res.data.data.next_page_url;
          this.$toast.clear();
        })
        .catch((err) => {
          this.$toast.fail(err);
          this.$toast.clear();
        });
    }
  },
};
</script>

<style lang="scss" scoped>
.userLike {
  background-color: #f2f2f2;
  padding: 10px 7.5px;
}

.none {
  font-size: 16px;
  color: #999;
  margin-top: 50px;
  text-align: center;
}
</style>
